package com.cloud.rocketmqtxconsumer.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component("delMessageListener")
public class DLQOrderMessageListener implements MessageListenerConcurrently {
    @Override
    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
        log.info("死信队列监听到消息...");
        try{
            for (MessageExt msg : msgs) {
                log.info("开始处理死信队列的消息....");
                System.out.println("发送短信、邮件，来通知人工处理");
            }
           return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }catch (Exception e){
            log.error("死信队列有消息处理失败....");
            return ConsumeConcurrentlyStatus.RECONSUME_LATER;
        }
    }
}
